﻿using Microsoft.VisualStudio.TestTools.UnitTesting;
using VCDIFF;
using VCDIFF.Rebuild;

namespace VCDIFF.Tests
{
    
    
    /// <summary>
    ///This is a test class for RebuildHeaderTest and is intended
    ///to contain all RebuildHeaderTest Unit Tests
    ///</summary>
    [TestClass()]
    public class RebuildHeaderTest
    {


        private TestContext testContextInstance;

        /// <summary>
        ///Gets or sets the test context which provides
        ///information about and functionality for the current test run.
        ///</summary>
        public TestContext TestContext
        {
            get
            {
                return testContextInstance;
            }
            set
            {
                testContextInstance = value;
            }
        }

        #region Additional test attributes
        // 
        //You can use the following additional attributes as you write your tests:
        //
        //Use ClassInitialize to run code before running the first test in the class
        //[ClassInitialize()]
        //public static void MyClassInitialize(TestContext testContext)
        //{
        //}
        //
        //Use ClassCleanup to run code after all tests in a class have run
        //[ClassCleanup()]
        //public static void MyClassCleanup()
        //{
        //}
        //
        //Use TestInitialize to run code before running each test
        //[TestInitialize()]
        //public void MyTestInitialize()
        //{
        //}
        //
        //Use TestCleanup to run code after each test has run
        //[TestCleanup()]
        //public void MyTestCleanup()
        //{
        //}
        //
        #endregion


        /// <summary>
        ///A test for Rebuild
        ///</summary>
        [TestMethod()]
        public void RebuildTest()
        {
            RebuildHeader target = new RebuildHeader();
            byte[] headerData = new byte[30];
            headerData[0] = 0xD6;
            headerData[1] = 0xC3;
            headerData[2] = 0xC4;
            headerData[3] = 0x01;
            headerData[4] = 0x02;
            headerData[5] = 0x03;
            headerData[6] = 0x04;
            headerData[7] = 0x05;
            headerData[8] = 0x06;

            headerData[9] = 0x01;
            headerData[10] = 0x8B;
            headerData[11] = 0x2E;
            headerData[12] = 0x00;
            headerData[13] = 0x10;
            headerData[14] = 0x96;
            headerData[15] = 0x5D;
            headerData[16] = 0x00;
            headerData[17] = 0x01;
            headerData[18] = 0x07;
            headerData[19] = 0x02;
            headerData[20] = 0x0A;
            headerData[21] = 0x73;
            headerData[22] = 0x8B;
            headerData[23] = 0x2E;
            headerData[24] = 0x02;
            headerData[25] = 0x73;
            headerData[26] = 0x8B;
            headerData[27] = 0x2E;
            headerData[28] = 0x00;
            headerData[29] = 0x00;

            Header expected = new Header();
            expected.Header1 = 0xD6;
            expected.Header2 = 0xC3;
            expected.Header3 = 0xC4;
            expected.Header4 = 0x01;
            expected.HdrIndicator = 0x02;
            expected.SecondaryCompressorId = 0x03;
            expected.CodeTableDataLength = 0x04;
            expected.NearCacheSize = 0x05;
            expected.SameCacheSize = 0x06;

            Header actual = target.Rebuild(headerData);
            bool same = true;

            if (expected.Header1 != actual.Header1)
                same = false;
            if (expected.Header2 != actual.Header2)
                same = false;
            if (expected.Header3 != actual.Header3)
                same = false;
            if (expected.Header4 != actual.Header4)
                same = false;
            if (expected.HdrIndicator != actual.HdrIndicator)
                same = false;
            if (expected.SecondaryCompressorId != actual.SecondaryCompressorId)
                same = false;
            if (expected.CodeTableDataLength != actual.CodeTableDataLength)
                same = false;
            if (expected.NearCacheSize != actual.NearCacheSize)
                same = false;
            if (expected.SameCacheSize != actual.SameCacheSize)
                same = false;

            Assert.AreEqual(true, same);
        }

        /// <summary>
        ///A test for HasHeaderData
        ///</summary>
        [TestMethod()]
        public void HasHeaderDataTest()
        {
            RebuildHeader target = new RebuildHeader();
            byte[] headerData = new byte[30];
            headerData[0] = 0xD6;
            headerData[1] = 0xC3;
            headerData[2] = 0xC4;
            headerData[3] = 0x01;
            headerData[4] = 0x02;
            headerData[5] = 0x03;
            headerData[6] = 0x04;
            headerData[7] = 0x05;
            headerData[8] = 0x06;

            headerData[9] = 0x01;
            headerData[10] = 0x8B;
            headerData[11] = 0x2E;
            headerData[12] = 0x00;
            headerData[13] = 0x10;
            headerData[14] = 0x96;
            headerData[15] = 0x5D;
            headerData[16] = 0x00;
            headerData[17] = 0x01;
            headerData[18] = 0x07;
            headerData[19] = 0x02;
            headerData[20] = 0x0A;
            headerData[21] = 0x73;
            headerData[22] = 0x8B;
            headerData[23] = 0x2E;
            headerData[24] = 0x02;
            headerData[25] = 0x73;
            headerData[26] = 0x8B;
            headerData[27] = 0x2E;
            headerData[28] = 0x00;
            headerData[29] = 0x00;

            bool expected = true;
            bool actual = target.HasHeaderData(headerData);

            Assert.AreEqual(expected, actual);
        }

        /// <summary>
        ///A test for HasHeaderData
        ///</summary>
        [TestMethod()]
        public void HasHeaderDataTest1()
        {
            RebuildHeader target = new RebuildHeader();
            byte[] headerData = new byte[30];
            headerData[0] = 0xD6;
            headerData[1] = 0xC3;
            headerData[2] = 0xC3;
            headerData[3] = 0x01;
            headerData[4] = 0x02;
            headerData[5] = 0x03;
            headerData[6] = 0x04;
            headerData[7] = 0x05;
            headerData[8] = 0x06;

            headerData[9] = 0x01;
            headerData[10] = 0x8B;
            headerData[11] = 0x2E;
            headerData[12] = 0x00;
            headerData[13] = 0x10;
            headerData[14] = 0x96;
            headerData[15] = 0x5D;
            headerData[16] = 0x00;
            headerData[17] = 0x01;
            headerData[18] = 0x07;
            headerData[19] = 0x02;
            headerData[20] = 0x0A;
            headerData[21] = 0x73;
            headerData[22] = 0x8B;
            headerData[23] = 0x2E;
            headerData[24] = 0x02;
            headerData[25] = 0x73;
            headerData[26] = 0x8B;
            headerData[27] = 0x2E;
            headerData[28] = 0x00;
            headerData[29] = 0x00;

            bool expected = false;
            bool actual = target.HasHeaderData(headerData);

            Assert.AreEqual(expected, actual);
        }

        /// <summary>
        ///A test for GetHeaderData
        ///</summary>
        [TestMethod()]
        public void GetHeaderDataTest()
        {
            RebuildHeader target = new RebuildHeader();
            byte[] headerData = new byte[30];
            headerData[0] = 0xD6;
            headerData[1] = 0xC3;
            headerData[2] = 0xC4;
            headerData[3] = 0x01;
            headerData[4] = 0x02;
            headerData[5] = 0x03;
            headerData[6] = 0x04;
            headerData[7] = 0x05;
            headerData[8] = 0x06;

            headerData[9] = 0x01;
            headerData[10] = 0x8B;
            headerData[11] = 0x2E;
            headerData[12] = 0x00;
            headerData[13] = 0x10;
            headerData[14] = 0x96;
            headerData[15] = 0x5D;
            headerData[16] = 0x00;
            headerData[17] = 0x01;
            headerData[18] = 0x07;
            headerData[19] = 0x02;
            headerData[20] = 0x0A;
            headerData[21] = 0x73;
            headerData[22] = 0x8B;
            headerData[23] = 0x2E;
            headerData[24] = 0x02;
            headerData[25] = 0x73;
            headerData[26] = 0x8B;
            headerData[27] = 0x2E;
            headerData[28] = 0x00;
            headerData[29] = 0x00;

            byte[] expected = new byte[9] { 0xD6, 0xC3, 0xC4, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06 };
            byte[] actual;
            actual = target.GetHeaderData(headerData);
            bool same = true;

            if (expected.Length != actual.Length)
                same = false;
            else
                for (int i = 0; i < expected.Length; i++)
                    if (expected[i] != actual[i])
                        same = false;

            Assert.AreEqual(true, same);
        }

        /// <summary>
        ///A test for RebuildHead
        ///</summary>
        [TestMethod()]
        public void RebuildHeadTest()
        {
            RebuildHeader target = new RebuildHeader();
            byte[] headerData = new byte[30];
            headerData[0] = 0xD6;
            headerData[1] = 0xC3;
            headerData[2] = 0xC4;
            headerData[3] = 0x01;
            headerData[4] = 0x02;
            headerData[5] = 0x03;
            headerData[6] = 0x04;
            headerData[7] = 0x05;
            headerData[8] = 0x06;

            headerData[9] = 0x01;
            headerData[10] = 0x8B;
            headerData[11] = 0x2E;
            headerData[12] = 0x00;
            headerData[13] = 0x10;
            headerData[14] = 0x96;
            headerData[15] = 0x5D;
            headerData[16] = 0x00;
            headerData[17] = 0x01;
            headerData[18] = 0x07;
            headerData[19] = 0x02;
            headerData[20] = 0x0A;
            headerData[21] = 0x73;
            headerData[22] = 0x8B;
            headerData[23] = 0x2E;
            headerData[24] = 0x02;
            headerData[25] = 0x73;
            headerData[26] = 0x8B;
            headerData[27] = 0x2E;
            headerData[28] = 0x00;
            headerData[29] = 0x00;

            Header expected = new Header();
            expected.Header1 = 0xD6;
            expected.Header2 = 0xC3;
            expected.Header3 = 0xC4;
            expected.Header4 = 0x01;
            expected.HdrIndicator = 0x02;
            expected.SecondaryCompressorId = 0x03;
            expected.CodeTableDataLength = 0x04;
            expected.NearCacheSize = 0x05;
            expected.SameCacheSize = 0x06;

            Header actual = target.RebuildHead(headerData);
            bool same = true;

            if (expected.Header1 != actual.Header1)
                same = false;
            if (expected.Header2 != actual.Header2)
                same = false;
            if (expected.Header3 != actual.Header3)
                same = false;
            if (expected.Header4 != actual.Header4)
                same = false;
            if (expected.HdrIndicator != actual.HdrIndicator)
                same = false;
            if (expected.SecondaryCompressorId != actual.SecondaryCompressorId)
                same = false;
            if (expected.CodeTableDataLength != actual.CodeTableDataLength)
                same = false;
            if (expected.NearCacheSize != actual.NearCacheSize)
                same = false;
            if (expected.SameCacheSize != actual.SameCacheSize)
                same = false;

            Assert.AreEqual(true, same);
        }

        /// <summary>
        ///A test for RebuildHeader Constructor
        ///</summary>
        [TestMethod()]
        public void RebuildHeaderConstructorTest()
        {
            RebuildHeader target = new RebuildHeader();
        }

        /// <summary>
        ///A test for GetHeaderSize
        ///</summary>
        [TestMethod()]
        public void GetHeaderSizeTest()
        {
            RebuildHeader target = new RebuildHeader();
            byte[] headerData = new byte[30];
            headerData[0] = 0xD6;
            headerData[1] = 0xC3;
            headerData[2] = 0xC3;
            headerData[3] = 0x01;
            headerData[4] = 0x02;
            headerData[5] = 0x03;
            headerData[6] = 0x04;
            headerData[7] = 0x05;
            headerData[8] = 0x06;

            headerData[9] = 0x01;
            headerData[10] = 0x8B;
            headerData[11] = 0x2E;
            headerData[12] = 0x00;
            headerData[13] = 0x10;
            headerData[14] = 0x96;
            headerData[15] = 0x5D;
            headerData[16] = 0x00;
            headerData[17] = 0x01;
            headerData[18] = 0x07;
            headerData[19] = 0x02;
            headerData[20] = 0x0A;
            headerData[21] = 0x73;
            headerData[22] = 0x8B;
            headerData[23] = 0x2E;
            headerData[24] = 0x02;
            headerData[25] = 0x73;
            headerData[26] = 0x8B;
            headerData[27] = 0x2E;
            headerData[28] = 0x00;
            headerData[29] = 0x00;

            ulong expected = 9;
            ulong actual = target.GetHeaderSize(headerData);
            Assert.AreEqual(expected, actual);
        }
    }
}
